<!-- application/views/scripts/blog/index.phtml -->
<script type="text/javascript">

$().ready(function() {

<!-- submenu of blog -->
	<?php 
		$catList="<a href='#' onclick='showCategory(null)'>Show All</a><br>";
		for($i=0; $i<count($this->categories);$i++) {
    		$catList=$catList."<a href='#' onclick='showCategory(".$this->categories[$i]['cat_id'].")'>"
    		.$this->categories[$i]['category']."(".$this->categories[$i]['count'].")</a><br>";
    	}    		
	?>

	$("#submenu_blog").append("<?php echo $catList;?>");

	<!-- tag cloud-->
	<?php 
	    $maxCount = 1;
	    foreach ($this->tags as $tag) {
	    	if ($tag['count'] > $maxCount) {
	    		$maxCount = $tag['count'];
	    	}
	    }
	    $minFont=8.0;
	    $fontRange=20.0;
		$tagCloud="<div class='ui-widget-header'>Tag</div>";
		foreach ($this->tags as $tag) {
			$fontSize = $minFont + $fontRange*$tag['count']/$maxCount;
			$tagCloud = $tagCloud. "<a href='#' onclick='showTag(".$tag['tid'].")' ";
			$tagCloud = $tagCloud. " style='font-size: ".$fontSize."pt'>";
			$tagCloud = $tagCloud. $tag['tag']."</a>&nbsp;&nbsp;";		
		}
	?>

	$("#rside-bar").append("<?php echo $tagCloud; ?>");
});




function showTag(tagId) {
	window.location.href="/blog?tagId=" + tagId;
}

function showCategory(catId) {
	if(catId != null) {
		window.location.href="/blog?catId=" + catId;
	} else {
		window.location.href="/blog";
	}
}

function editBlog(bid) {
	showAddBlog(1);	
	setValueForBlogForm(bid,$("span#blog-title_" + bid).text(),
			$("div#blog-body_" + bid).html(),
			$("span#blog-tag_" + bid).text(),
			$("span#blog-category_" + bid).text(),
			$("span#blog-privilege_" + bid).text());
}

</script>
<div id="operation-bar">
<?php 
if (isset($_SESSION['userinfo'])) {?>
<a href="#" onclick="showAddBlog(1);">post a blog</a>
<?php }?>
</div>

<div id="info-bar"> 
<?php
if ($this->selectedCategory) {
	echo "Selected Category => ".$this->selectedCategory ."&nbsp;&nbsp;&nbsp;<a href='/blog'>clear</a>";
}
if ($this->selectedTag) {
	echo "Selected Tags => ".$this->selectedTag ."&nbsp;&nbsp;&nbsp;<a href='/blog'>clear</a>";
}
?>
</div>

<?php echo $this->render('/blog/edit.phtml');?>

<?php echo $this->render('paging.phtml');?>
<div id="blogs">
<?php 
$blogs = $this->allBlogs;

for ($i=0; $i<sizeof($blogs); $i++) {
	echo "<div class='blog-entry'>";
	echo "<div class='blog-title ' > <span id='blog-title_".$blogs[$i]->getBid()."'>".$blogs[$i]->getTitle()."</span><a href='/blog/view?blogId=".$blogs[$i]->getBid()."'>&gt;&gt;&gt;</a></div>";
	echo "<div class='blog-date'>作者：".$blogs[$i]->getOwnerName()
	."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Created: ".$blogs[$i]->getCreateDate()
	."&nbsp;&nbsp;Updated: ".$blogs[$i]->getUpdateDate()."</div>";
	if (isset($_SESSION['userinfo'])) {
		echo "<div class='blog-operation'><a href='#' onclick='editBlog(".$blogs[$i]->getBid().")'>edit</a>&nbsp;|&nbsp;"
		."<a href='/blog/delete?blogId=".$blogs[$i]->getBid()."'>delete</a>&nbsp;|&nbsp;";
		echo "权限: <span id='blog-privilege_".$blogs[$i]->getBid()."'>";
		if(Application_Model_Constants::PRIVILEGE_TYPE_PUBLIC == $blogs[$i]->getPrivilegeType()) {
			echo Application_Model_Constants::PRIVILEGE_TYPE_PUBLIC_STR;
		} else {
			echo Application_Model_Constants::PRIVILEGE_TYPE_PRIVATE_STR;
		}
		echo "</span></div>";
	}
	echo "<p><div class='blog-content' id='blog-body_".$blogs[$i]->getBid()."'>".$blogs[$i]->getContent()."</div></p>";
	echo "<div class='blog-footer'> Category:&nbsp;<span class='blog-category' id='blog-category_".$blogs[$i]->getBid()."'>".
		"<a href='#' onclick='showCategory(".$blogs[$i]->getCategoryId().")'>".$blogs[$i]->getCategory()."</a>".
		"</span>&nbsp;&nbsp;";
	echo "Tags:&nbsp;<span class='blog-tag' id='blog-tag_".$blogs[$i]->getBid()."'>";
	foreach ($blogs[$i]->getTags() as $tag) {
	 echo "<a href='#' onclick='showTag(".$tag['tid'].")'>".$tag['tag']."</a>"."&nbsp;";
	}
	echo "</span>";//blog-tag
	echo "</div>";
	echo "</div>";//blog-entry
}

?>
</div>
<?php echo $this->render('paging.phtml');?>

